package com.cos.openapi.web.controller;

import com.cos.openapi.dao.CustomerMapper;
import com.cos.openapi.entity.Customer;
import com.cos.openapi.pojo.JsonResult;
import com.cos.openapi.pojo.TableResult;
import com.cos.openapi.services.CustomerServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: COS
 * @time: 2021/2/1 9:07
 * @description:
 */
@RestController
@RequestMapping("/sys/customer")
public class CustomerController {
    @Autowired
    private CustomerServices customerServices;
    @RequestMapping("/table")
    public TableResult table(@RequestParam(defaultValue = "1") Integer page,
                             @RequestParam(defaultValue = "10") Integer limit, String name, Integer state) {
        try {
            //访问业务层 请求
            return customerServices.getCustomerByNameAndState(page,limit,name, state);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return TableResult.getResultByFail("出错了");
    }

    @RequestMapping("/update")
    public JsonResult update(Customer customer){
        //访问业务层进行修改操作
        return customerServices.update(customer);
    }
    @RequestMapping("/add")
    public JsonResult add(Customer customer){
        //访问业务层进行修改操作
        return customerServices.add(customer);
    }

    @RequestMapping("/del")
    public JsonResult del(Integer[] ids){
        //访问业务层进行删除
        return customerServices.del(ids);
    }
}
